﻿using System;
using System.Collections.Generic;

namespace MyLib.Web {
	/// <summary>
	/// 
	/// </summary>
	public abstract class MyMasterPage : System.Web.UI.MasterPage {
		/// <summary>
		/// 
		/// </summary>
		public class MessagesChangedEventArgs : EventArgs {
			/// <summary>
			/// 
			/// </summary>
			public string[] Messages {
				get;
				private set;
			}

			/// <summary>
			/// 
			/// </summary>
			/// <param name="messages"></param>
			internal MessagesChangedEventArgs(string[] messages) {
				Messages = messages;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string SubTitle {
			get;
			set;
		}

		private string[] m_errorMessages;

		private string[] m_warningMessages;

		private string[] m_infoMessages;

		/// <summary>
		/// 
		/// </summary>
		public string[] ErrorMessages {
			get {
				return m_errorMessages;
			}

			set {
				if (value == null)
					m_errorMessages = new string[0];
				else
					m_errorMessages = value;

				OnErrorMessagesChanged();
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string[] WarningMessages {
			get {
				return m_warningMessages;
			}

			set {
				if (value == null)
					m_warningMessages = new string[0];
				else
					m_warningMessages = value;

				OnWarningMessagesChanged();
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string[] InfoMessages {
			get {
				return m_infoMessages;
			}

			set {
				if (value == null)
					m_infoMessages = new string[0];
				else
					m_infoMessages = value;

				OnInfoMessagesChanged();
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public event EventHandler<MessagesChangedEventArgs> ErrorMessagesChanged;

		/// <summary>
		/// 
		/// </summary>
		public event EventHandler<MessagesChangedEventArgs> WarningMessagesChanged;

		/// <summary>
		/// 
		/// </summary>
		public event EventHandler<MessagesChangedEventArgs> InfoMessagesChanged;

		/// <summary>
		/// 
		/// </summary>
		protected virtual void OnErrorMessagesChanged() {
			if (ErrorMessagesChanged != null)
				ErrorMessagesChanged(this, new MessagesChangedEventArgs(ErrorMessages));
		}

		/// <summary>
		/// 
		/// </summary>
		protected virtual void OnWarningMessagesChanged() {
			if (WarningMessagesChanged != null)
				WarningMessagesChanged(this, new MessagesChangedEventArgs(WarningMessages));
		}

		/// <summary>
		/// 
		/// </summary>
		protected virtual void OnInfoMessagesChanged() {
			if (InfoMessagesChanged != null)
				InfoMessagesChanged(this, new MessagesChangedEventArgs(InfoMessages));
		}

	} // end of MyMasterPage.
}
